<!-- 编辑弹窗 -->
<template>
    <ele-modal
      inner
      width="80%"
      :movable="false"
      :visible="visible"
      :close-on-click-modal="true"
      :before-close="handleClose"
      custom-class="ele-dialog-form"
      :title="isUpdate ? '客户应付账款明细' : '客户应付账款明细'"
      @update:visible="updateVisible"
    >
    <div class="ele-body">
      <el-card>
        <ele-pro-table ref="table"  row-key="id" :columns="warehouseItemColumns"  :datasource="datasource"  :need-page="true"  :height="tableHeight" :full-height="tableFullHeight">
          <template slot="toolbar">
          </template>
          <template slot="orderNo" slot-scope="{ row }"  >
            <el-link  type="primary"   @click="clickbillNo(row)" >{{ row.orderNo }}</el-link>
          </template>
          <!-- 操作列 -->
          <template slot="action" slot-scope="{ row }"  >
            <el-popconfirm v-show="row.status !=5" class="ele-action" title="确定要作废吗？"  @confirm="remove(row)"  >
              <el-link type="danger" slot="reference" :underline="false"  icon="el-icon-delete" >作废</el-link>
            </el-popconfirm>
          </template>
        </ele-pro-table>
      </el-card>
    </div>
    </ele-modal>
  </template>
  <script>

  //初始化对像
  import { removePageTab } from '@/utils/page-tab-util';
  import { QueryRecreceiptitemByCondition,DeleteRecreceiptItem } from '@/api/finance/recreceipt';

  export default {
    name: 'paycustomeraccountitemList',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data: Object,
    },
    data() {
      return {
        // 表单数据
        form: {},
        fixedHeight:true,
        // 提交状态
        loading: false,
        current:null,
        // 是否是修改
        isUpdate: false,
        showEdit:false,
        // 表格列配置
        warehouseItemColumns: [
          {columnKey: 'index', type: 'index', width: 50, align: 'center', showOverflowTooltip: true, fixed: 'left', label:'序号',},
          {prop: 'orderNo', label: '单据编号',showOverflowTooltip: true, align: 'center', sortable: 'orderNo', slot: 'orderNo'},
          {prop: 'customerName', label: '客户名称', showOverflowTooltip: true, align: 'center', sortable: 'customerName'},
          {
            prop: 'recDate', label: '付款日期', showOverflowTooltip: true, align: 'center',sortable: 'recDate',
            formatter: (row, column, cellValue) => {return this.$util.toDateString(cellValue,"YYYY-MM-DD");}
          },
          {prop: 'paybankAccountDesc', label: '付款账户',showOverflowTooltip: true, align: 'center', sortable: 'bankAccountId'},
          {prop: 'amount', label: '金额', showOverflowTooltip: true,sortable:'amount', align: 'center',},
          {prop: 'currencyDesc', label: '币种',showOverflowTooltip: true, align: 'center', sortable: 'currencyId'},
          {prop: 'rate', label: '汇率',showOverflowTooltip: true, align: 'center', sortable: 'rate'},
          {prop: 'amountCn', label: '付款金额(￥)',showOverflowTooltip: true, align: 'center', sortable: 'amountCn'},
          {prop: 'action', label: '操作',showOverflowTooltip: true, align: 'center', slot:'action'},
        ],
      };
    },
    computed: {
        // 表格高度
        tableHeight() {
          var fh = this.fixedHeight ? 'calc(100vh - 350px)' : void 0;
          return fh;
        },
        // 表格全屏时高度
        tableFullHeight() {
          var fh =  this.fixedHeight ? 'calc(100vh - 250px)' : null;
          return fh;
        },
      },
    methods: {

      /* 表格数据源 */
      async datasource(params) {

        params.where.pageindex = params.page;
        params.where.pagesize = params.limit;

        //添加排序
        if(params.order.order == null || params.order.order == undefined){
          params.where.orderBys = [{ sort: "createDate", order: 1, }];
        }else{
          params.where.orderBys = [];
          params.where.orderBys.push({sort:params.sorter.column.sortable,order:params.order.order=='asc'?0:1});
        }

        if(!params.where.conditions) params.where.conditions = [];
        
        if(this.form.orderId){
          params.where.conditions.push({
            key:"orderId",
            operator: 0,
            value:  this.form.orderId,
          });
        }

        params.where.conditions.push({
          key:"recreceiptType",
          operator: 0,
          value:  2,
        });

        params.where.conditions.push({
          key:"deleted",
          operator: 0,
          value:  0,
        });

        let data = await QueryRecreceiptitemByCondition(params.where);
      
        this.$nextTick(() => {
            this.$refs.table.doLayout();
          });
        return {
            list:data.items,
            count:data.totalrecords,
        };
      },
      //单击单号
      clickbillNo(row){
        
        removePageTab({ key: '/businesshandling/saleoutmanager' });
        this.$nextTick(() => {
          this.$router.push({path: '/businesshandling/saleoutmanager', query: { "orderNo": row.orderNo } });
        });
      },

      /* 更新visible */
      updateVisible(value) {
        //更新父组件中的visible的值
        this.$emit('update:visible', value);
        //更新文件列表对像
      },

      handleClose(){
        this.$emit('update:visible', false);
      },

      /* 刷新表格 */
      reload(where) {
        if(this.$refs.table){
          this.$refs.table.reload({ where: where });
        }
      },

      /* 删除 */
      remove(row) {
        const loading = this.$loading({ lock: true });
        DeleteRecreceiptItem(row.id)
          .then((msg) => {
            loading.close();
            this.$message.success(msg);
            this.updateVisible(false);
             //回调父组件方法
             this.$emit('done');
          })
          .catch((e) => {
            loading.close();
            this.$message.error(e.message);
          });
      },
  },
    
    /* 监听visible属性变化 */
    watch: {
      visible(visible) {
        if (visible) {
          if (this.data && this.data.id) {
            //赋值this.form
            this.form = this.data;
            this.isUpdate = this.data.id !=null && this.data.id !=undefined;

            this.reload();
          } 
        } 
      }
    }
  };
  </script>